`
https://leetcode.cn/problems/sort-colors/
`

/**
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var sortColors = function (nums) {
  const len = nums.length

  // 三路快排的切分逻辑

  // all in nums[0 ... zero] === 0
  // all in nums(zero ... i) === 1
  // all in nums[two ... len-1] === 2
  let zero = -1
  let two = len
  for (let i = 0; i < two;) {
    if (nums[i] === 0) {
      zero++
      [nums[i], nums[zero]] = [nums[zero], nums[i]]
      i++
    } else if (nums[i] === 1) {
      i++
    } else {
      // nums[i] === 2
      two--
      [nums[i], nums[two]] = [nums[two], nums[i]]
    }
  }
};